//我的资讯
var isover=0;
var username;//用户中文名
var currentIndex=1;//页码
$().ready(function(){
    $.ajax({
        type: "post",
        datatype: "json",
        url: userurl,
        data:{"userId":id},
        success:function(data){
            username=data.Data.nick;
            aj();
        }
    });
});
$(".mweb_modal_back_button").click(function(){
    if(document.referrer){history.go(-1);}
    else{location.href="setpage.html";}
});
function showloadimg(e){e.style.display="block";}
var ajaxrunning="yes";//初始状态不可以滚动
function aj(){
    if(isover===0){
        ajaxrunning="yes";
        $.ajax({
            type:"get",
            datatype: "json",
            url: getMyNewsListUrl+"?userId="+id+"&pageSize=15&currentIndex="+currentIndex,
            success:function(d){
                console.log(d);
                if(d.Message==="没有数据"){
                    isover=1;//没有数据了
                    $("#waiting").css("display","none");
                    $("#nonews").css("display","block");
                }else{
                    if(d.Data&&d.Data.length>0){
                        if(d.Data.length<15){
                            $("#waiting").css("display","none");
                            $("#nonews").css("display","block");
                        }
                        var num=0;
                        for(var i=0;i<d.Data.length;i++){
                            num++;
                            if(num===d.Data.length){
                                ajaxrunning="no";
                            }
                            allnews(d.Data[i]);
                        }
                    }
                    else{
                        $("#waiting").css("display","none");
                        $("#nonews").css("display","block");
                    }
                }

            }
        })
    }
}
//删除
function delmynewsftn(e){
    shareid= e.dataset.shareid;
    $("#delmynews").css("display","block");
    $("body").attr("class","overflow");
}
$("#delmynewsok").click(function(){
    $("#mainp"+shareid).remove();
    $.ajax({
        type:"post",
        data:{"shareId":shareid},
        url:delmynewsurl,
        success:function(d){
            $("#delmynews").css("display","none");
            $("body").attr("class","");
        }
    })
});
$("#delmynewscancel").click(function(){
    shareid="";
    $("#delmynews").css("display","none");
    $("body").attr("class","");
});
//跳转
function newsgohref(e){
    if(e.dataset.id){
        var pcUrl=true;
        var errorUrl=/环球网|1905电影网|中国会计视野|编织人生网|IT之家|优姿美女/;
        if(e.dataset.sitename){
            if(errorUrl.test(e.dataset.sitename)){pcUrl=false;}
        }
        var neid=e.dataset.id;
        var shareuserid="";
        if(e.dataset.shareid){
            shareuserid="#newsShareId="+e.dataset.shareid;
        }

        if(pcUrl){goClick3Url="newsdetail.html?newsid="+neid+"#fromuser="+$.cookie("MYID")+shareuserid;}
        else{goClick3Url="http://www.pulu.com/weixin/newsdetail.html?newsid="+neid+"#fromuser="+$.cookie("MYID")+shareuserid;}
        location.href=goClick3Url;
    }
}
function allnews(d){
    //用户转发新闻有自己的评论
    var uview="";
    var desword="自动转发";
    var desReg=new RegExp(desword);
    if(d.des&&!desReg.test(d.des)){
        var newcontentcode=codetoface(d.des);//文字中插入表情图片
        uview="<div class='info_wrapper senderview'><div class='info'><span class='feed_item_answer_user'>"+newcontentcode+"</span></div></div>";
    }

    //时间
    var datatime="";
    if(d.shareTime){datatime=getDateDiff(getDateTimeStamp(d.shareTime));}
    if(!datatime||datatime=="undefined"){datatime="刚刚"};

    //自己的经验可以删除
    var delbtn='<div class="delnews rt" onclick="delmynewsftn(this)" data-shareid="'+d.shareId+'">×</div>';

    //新闻有图片
    var newsimgurl="img/puluweixin.jpg";
    if(d.newsImg){newsimgurl=d.newsImg;}
    var imgword="<div class='feed_answer_preview answer_content'><h2 class='no_highlight'><a class='question_link hrefto' onclick='newsgohref(this)' data-sitename='"+d.siteName+"' data-id='"+d.qid+"' data-typeid='"+d.newsTypeId+"' data-shareid='"+d.shareId+"' data-euser='"+d.shareUserId+"' data-enick='"+d.shareUserNick+"'><span class='question_text'><span class='rendered_qtext'>"+d.title+"</span></span></a></h2><a onclick='newsgohref(this)' data-sitename='"+d.siteName+"' data-id='"+d.qid+"' data-typeid='"+d.newsTypeId+"' data-shareid='"+d.shareId+"' data-euser='"+d.shareUserId+"' data-enick='"+d.shareUserNick+"'><div class='truncated_newsImgnail_holder'><span class='rendered_qtext'><div class='qtext_image_wrapper'><canvas class='qtext_image_placeholder landscape qtext_image zoomable_in_feed' width='500' height='500' style='visibility: hidden;'></canvas><img class='landscape qtext_image zoomable_in_feed lazy_loaded lazy_loading' src='"+newsimgurl+"' onload='showloadimg(this)' style='display:none;'></div></span></div></a></div>";

    //加载数据
    $("#questionlist").append("<div class='pagedlist_item' id='mainp"+d.shareId+"'> <div class='feed_item feed_type_answer'>"+"<div class='ContentHeader'> <div class='photo_info_layout size_small'> <div class='info_wrapper'>"+delbtn+"<div class='ContentFooter'>"+ d.shareUserNick+" · "+datatime+"</div></div> </div> </div> "+uview+"<div class='Answer'><div class='QuestionAnswerVerbose SimpleToggle Toggle'>"+imgword+"<div class='ActionBar'><div class='action_bar_inner' >"+"<div class='actionlist' id='actionlist"+d.shareId+"'>"+"<div id='shareid"+d.shareId+"' data-shareid='"+d.shareId+"' class='addnewscom'>"+d.count+" 浏览  "+ "</div>"+"</div></div></div></div></div></div></div>");
};
$(window).scroll(function(){
    var mainheight=$(".home_feed").height();
    var windowheight=$(window).height();
    var chajuli=$(".home_feed").offset().top - $(window).scrollTop();
    var cz=windowheight-mainheight+50;
    if(chajuli<cz&&ajaxrunning==="no"){
        console.log(ajaxrunning);
        currentIndex++;
        aj();
    }
});